<template>
  <div>
    <el-card class="noDone">
      <el-row type="flex">
        <el-col :span="12" class="title">待执行任务</el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="24" class="task">
          <el-table :data="NoDoneList" type="flex" style="width: 100%" border max-height="250">
            <el-table-column prop="serialNumber" label="序号" width="80" align="center"></el-table-column>
            <el-table-column prop="projectName" label="名称" width="480" align="center"></el-table-column>
            <!-- <el-table-column prop="state" label="任务状态" align="center">
              <template slot-scope="scope">
                <el-tag size="medium" :type="
                  scope.row.state == 1 ? 'danger' :
                    scope.row.state == 2 ? 'warning' :
                      scope.row.state == 3 ? 'success' :
                        scope.row.state == 4 ? '' :
                          scope.row.state == 5 ? 'info' : 
                          scope.row.state == null ? '' : ''">
                  {{
                    scope.row.state == 1 ? '已延期' :
                    scope.row.state == 2 ? '即将到期' :
                      scope.row.state == 3 ? '未到期' :
                        scope.row.state == 4 ? '已暂停' :
                          scope.row.state == 5 ? '已完成' :
                          scope.row.state == null ? '-' : ''
                  }}
                </el-tag>
              </template>
            </el-table-column> -->
            <el-table-column prop="endDate" label="截止时间" align="center"></el-table-column>
            <el-table-column prop="principalName" label="责任人" align="center"></el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button @click="todoReceive(scope.row)">领任务</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import bus from "@/components/bus";
import { toBeExecuted, receiveTask, receiveTaskInfo } from "../../../../service/workbenchApi";

export default {
  name: "",
  props: [""],
  components: {},
  data() {
    return {
      NoDoneList: [],
      taskId: 0, // 任务id
    };
  },
  methods: {
    // 领任务
    todoReceive(row) {
      this.taskId = row.id;
      this.NoDoneList = [];
      if (row.isTask == 1) {
        receiveTaskInfo(this.taskId).then((res) => {
          this.$message.success("领取成功!");
          bus.$emit("receiveTask");
          this.getData();
        });

      } else {
        receiveTask(this.taskId).then((res) => {
          this.$message.success("领取成功!");
          bus.$emit("receiveTask");
          this.getData();
        });
      }
    },
    getData() {
      //待执行任务
      toBeExecuted().then((res) => {
        if (res.code == 0) {
          this.NoDoneList = res.data;
        }
      });
    },
  },
  created() {
    this.getData();
  },
};
</script>

<style lang="scss" scoped>
.noDone {
  width: 100%;
  margin-top: 10px;
  margin-bottom: 20px;
  height: 320px;

  .title {
    font-size: 18px;
    color: #303133;
    font-weight: bold;
  }

  .task {
    margin-top: 10px;

    .el-button {
      background: rgba(240, 249, 235, 1);
      border: 1px solid rgba(194, 231, 176, 1);
      border-radius: 3px;
      color: #67c23a;
      font-size: 12px;
    }
  }
}
</style>